package ru.usu.gv.view;

import ru.usu.gv.gui.actions.DeleteVertexAction;
import ru.usu.gv.gui.frames.EditVertexFrame;
import ru.usu.gv.uicomponents.UIVertex;

import javax.swing.AbstractAction;
import javax.swing.JPopupMenu;

import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;

/**
 @author Sergey Pupyrev 
 01.04.2007
 */

public class PopupVertexPickingClient extends PickingClientBase<UIVertex>
{
	private JPopupMenu vertexPopupMenu = null;

	public void callback(MouseEvent e, UIVertex element)
	{
		if (!e.isMetaDown())
			return;

		initilizePopupMenu(element);
		vertexPopupMenu.show(e.getComponent(), e.getX(), e.getY());
		vertexPopupMenu.updateUI();
	}

	private void initilizePopupMenu(final UIVertex vertex)
	{
		vertexPopupMenu = new JPopupMenu();
		vertexPopupMenu.add(new AbstractAction("Редактировать")
		{
			public void actionPerformed(ActionEvent e)
			{
				new EditVertexFrame(vertex).setVisible(true);
			}
		});

		vertexPopupMenu.add(new AbstractAction("Удалить")
		{
			public void actionPerformed(ActionEvent e)
			{
				new DeleteVertexAction(vertex).execute();
			}
		});
	}

}
